package serverMessage;
import java.nio.channels.SocketChannel;
import java.util.HashSet;

import time.LogicalClock;
import time.LogicalTimeStamp;


public class UserRegistrationRecord {
	private SocketChannel socket;
	private LogicalTimeStamp reqTime=null;
	private String username;
	private String password;
	private byte[] bytes;
	private int bg;
	private String nickname;
	private HashSet<String> serversAgreed;
	
	public UserRegistrationRecord(SocketChannel socket, String username, String password){
		this.socket = socket;
		this.username = username;
		this.password = password;
		serversAgreed = new HashSet<String>();
	}
	
	public boolean hasServerAgreed(String serverName){
		return serversAgreed.contains(serverName);
	}
	
	public void addAgreedServer(String serverName){
		serversAgreed.add(serverName);
	}
	
	public HashSet<String> getAgreedServers(){
		return serversAgreed;
	}
	
	// the logical time in which the ME request is sent
	public void setRequestTime(LogicalTimeStamp ts){
		this.reqTime = ts;
	}
	
	public void setBytes(byte[] arr){
		this.bytes = arr;
	}
	public byte[] getBytes(){
		return bytes;
	}
	
	public int getBG() {
		return bg;
	}
	public void setBG(int bg) {
		this.bg = bg;
	}
	
	public String getNickname() {
		return nickname;
	}
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	
	public String getUsername(){	return this.username;	}
	public String getPassword(){	return this.password;	}
	public SocketChannel getSocket(){return this.socket;	}
	
	// return the logical time in which the ME request is sent
	//  null means the request has not yet been sent out
	public LogicalTimeStamp getRequestTime(){		return this.reqTime;	}
	
	public String toString(){
		StringBuffer str = new StringBuffer();
		str.append("UserRegistrationRecord. " + "username=" + this.username + " password=" + this.password);
		
		if (reqTime==null) {
			str.append(" writeME has not yet been requested");
		} else {
			str.append(" writeME requested at TS=" + this.reqTime);
		}
		return str.toString();
	}
}
